package com.yugong.controller;

import com.github.pagehelper.PageInfo;
import com.yugong.common.Result;
import com.yugong.entity.vo.request.CourseArrangeRequestVO;
import com.yugong.entity.vo.response.CourseArrangeListResponseVO;
import com.yugong.service.CourseArrangeService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 课程安排控制器类
 *
 * @author yugong
 * @date 2024/2/25
 */
@RestController
@RequestMapping("/api/course-arrange")
public class CourseArrangeController {
    @Resource
    private CourseArrangeService courseArrangeService;

    /**
     * 新增课程安排
     *
     * @param courseArrangeRequestVO 课程安排请求实体类
     * @return 响应码
     */
    @PostMapping("/add-course-arrange")
    public Result addCourseArrange(@RequestBody CourseArrangeRequestVO courseArrangeRequestVO) {
        int addFlag = courseArrangeService.addCourseArrange(courseArrangeRequestVO);
        return Result.success(addFlag);
    }

    /**
     * 查询课程安排
     *
     * @param pageNum           当前页
     * @param pageSize          当前页数据个数
     * @param orderClassAdminNo 订单班管理员工号
     * @param orderClassName    班名
     * @return 课程安排
     */
    @GetMapping("/find-course-arrange-page/{orderClassAdminNo}")
    public Result findCourseArrangePage(@RequestParam(defaultValue = "1") Integer pageNum,
                                        @RequestParam(defaultValue = "5") Integer pageSize,
                                        @PathVariable String orderClassAdminNo,
                                        @RequestParam String orderClassName) {
        PageInfo<CourseArrangeListResponseVO> courseArrangeListResponseVOPageInfo
                = courseArrangeService.findCourseArrangePage(pageNum, pageSize, orderClassAdminNo, orderClassName);
        return Result.success(courseArrangeListResponseVOPageInfo);
    }

    /**
     * 更新课程安排
     *
     * @param courseArrangeRequestVO 课程安排请求实体类
     * @return 响应码
     */
    @PutMapping("/update-course-arrange")
    public Result updateCourseArrange(@RequestBody CourseArrangeRequestVO courseArrangeRequestVO) {
        int updateFlag = courseArrangeService.updateCourseArrange(courseArrangeRequestVO);
        return Result.success(updateFlag);
    }

    /**
     * 删除课程安排
     *
     * @param courseArrangeNo 主键
     * @return 响应码
     */
    @DeleteMapping("/delete-course-arrange/{courseArrangeNo}")
    public Result deleteCourseArrange(@PathVariable Integer courseArrangeNo) {
        int deleteFlag = courseArrangeService.deleteCourseArrange(courseArrangeNo);
        return Result.success(deleteFlag);
    }
}
